package com.xiangyang.service.impl;

import com.xiangyang.annotations.OperationLog;
import com.xiangyang.entity.Drug;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.mapper.IDrugMapper;
import com.xiangyang.service.IDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugServicelmpl implements IDrugService {
    @Autowired
    private IDrugMapper durgMapper;

    //修改药品订单
    @Override
//    @OperationLog(title = "修改药品订单", businessType = "修改", oldDataMethod = "getData", newDataMethod = "getData")
    public String UpdateDrug(Drug prescription) {
        System.out.println(prescription);
        int updateOrder = durgMapper.updateDrug(prescription);
        if (updateOrder < 0 &&
                prescription.getFrequency() == null &&
                prescription.getDrugName() == null &&
                prescription.getCreatedAt() == null &&
                prescription.getDrugNumber() == null &&
                prescription.getCourseOfTreatment() == null &&
                prescription.getPrescriptionId() == null &&
                prescription.getDrugType()== null) {
            return "修改失败";
        }
        return "修改成功";
    }
    //删除药品订单
    @Override
//    @OperationLog(title = "删除药品订单", businessType = "删除", oldDataMethod = "getData")
    public String DeleteDrug(Long prescriptionId) {
        if (prescriptionId == null) {
            return "请输入要删除的药品编号";
        }
        int i = durgMapper.deleteDrug(prescriptionId);
        return i > 0 ? "删除成功" : "删除失败";
    }

    @Override
    public Result selectDrug() {
        return Result.ok(durgMapper.selectDrug());
    }




}
